/**
 * Created by liubin on 2014/8/31.
 */
define(['angular'], function (angular) {
    'use strict';
    return angular.module('app.directives', []).
        directive('alerts', function(){
            return {
                restrict: 'A',
                scope: {
                    // 绑定值
                    data : '=',
                    // 绑定函数
                    closeAlert : '&'
                },
                //transclude: true,
//                template : '<div class="alert" ng-repeat="alert in data"'+
//                'ng-class="{\'alert-info\':alert.info, \'alert-block\':alert.block, \'alert-warning\':alert.warning, \'alert-danger\': alert.danger}">' +
//                    '<button type="button" class="close" data-dismiss="alert"><i class="ace-icon fa fa-times"></i></button>'
//                    + '{{ alert.msg }}'
//                    + '<br/>'
//                    + '</div>'
//                    + '<div class="space"></div>'
                template: '<alert ng-repeat="alert in data" type="{{alert.type}}" close="closeAlert({index: $index})">' +
                    '{{ alert.msg }}' +
                    '</alert>' +
                    '<div class="space"></div>'
//                link: function (scope, element) {
//                    scope.close = close;
//                 }
            }
        }).
        directive('appRequired', function(){
             return {
                 restrict: 'A',
                 link: function(scope, element, attrs) {
                     var rq = angular.element('<span class="help-inline col-xs-12 col-sm-7">' +
                                                '<span class="middle" style="color:red">*</span>' +
											    '</span>');
                     element.after(rq);
                 }
             }
        });
//        directive('jqGrid', function(){
//            return {
//                restrict: 'A',
//                scope: {
//                    config: '=',
//                    data : '='
//                },
//                link: function (scope, element, attrs) {
//                    var table;
//                    scope.$watch('config', function (newValue) {
//                        element.children().empty();
//                        table = angular.element('<table></table>');
//                        element.append(table);
//                        $(table).jqGrid(newValue);
//                    });
//
//                    scope.$watch('data', function (newValue, oldValue) {
//                        var i;
//                        for (i = oldValue.length - 1; i >= 0; i--) {
//                            $(table).jqGrid('delRowData', i);
//                        }
//                        for (i = 0; i < newValue.length; i++) {
//                            $(table).jqGrid('addRowData', i, newValue[i]);
//                        }
//                    });
//                }
//            }
//        });
});